<template>
	<view>
		<view class="submit">
			<view class="submit-chat">
				<view class="bt-img">
					<image :src="toc" @click="records"></image>
				</view>
				<textarea id="shuru" auto-height="true" class="chat-send btn" :class="{displaynone:isrecord}"
					@input="inputs" v-model="msg"></textarea>
				<view class="record btn" :class="{displaynone:!isrecord}">按住说话</view>
				<view class="bt-img" @click="add">
					<image src="../../static/tianjia.png"></image>
				</view>
				<view class="bt-img">
					<image src="../../static/biaoqing.png"></image>
				</view>
				<view class="enter" @click="enter">发送</view>
			</view>
			<view class="add" :class="{displaynone: isadd}">
				<dingdan @enterorder="enterorder" v-model="etr"></dingdan>
				<!-- <view class="add-cd">
					<view class="add-cd_" @click="fasongdd">
						<view class="fsdd">
							<image class="fsdd-dd" mode="aspectFill" src="../../static/dingdan.png"></image>
						</view>
						<view class="fsdd-d">发送订单</view>
					</view>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import dingdan from '../../components/dingdan/dingdan.vue'
	export default {
		components :{
			dingdan,
		},
		data() {
			return {
				etr:"",
				msg: "",
				isrecord: false,
				toc: "../../static/yyimg.png",
				isadd: true,
			}
		},
		methods: {
			//发送订单
			enterorder:function(e){
				this.$emit('enterorder', this.etr);
				setTimeout(() => {
					this.etr = '';
				}, 0);
				console.log(e);
			},

			
			//获取模块高度
			getElementHeight: function() {
				const query = uni.createSelectorQuery().in(this);
				query.select('.submit').boundingClientRect(data => {
					this.$emit('heights', data.height);
				}).exec();
			},
			//点击切换音频
			records: function() {
				if (this.isrecord) {
					this.isrecord = false;
					this.toc = "../../static/yyimg.png";
				} else {
					this.isrecord = true;
					this.toc = "../../static/jianpan.png";
				}
			},
			add: function() {
				this.isadd = !this.isadd;
				setTimeout(() => {
					this.getElementHeight();
				}, 0)

			},
			
			//文字发送
			enter:function(e){
				this.$emit('inputs', this.msg);
				setTimeout(() => {
					this.msg = '';
				}, 0);
			},
			inputs: function(e) {
				// var x = document.getElementById("shuru");
				var chatm = e.detail.value;
				var pos = chatm.indexOf('\n');
				if (pos != -1 && chatm.length > 1) {
					console.log(this.msg)
					this.$emit('inputs', this.msg);
					setTimeout(() => {
						this.msg = '';
					}, 0);

				}

			}

		}
	}
</script>

<style lang="scss">
	.submit {
		background-color: #f4f4f4;
		// background: rqba(244,244,244,0.96);
		border-top: 1px solid $uni-border-color;
		width: 100%;
		z-index: 1000;
		position: fixed;
		bottom: 0;
		z-index: 100;
		padding-bottom: var(--status-bar-height);

	}

	.submit-chat {
		
		width: 100%;


		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 14rpx 14rpx;
		.enter{
			font-size: 20rpx;
			flex: none;
			padding: 0 10rpx;
		}

		image {
			width: 56rpx;
			height: 56rpx;
			margin: 0 10rpx;
			flex: auto;
		}

		.btn {

			flex: auto;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 20rpx;
			max-height: 160rpx;
			margin: 0 10rpx;

		}

		.record {
			color: #757575;
			text-align: center;
			font-size: auto;

			flex: auto;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 20rpx;

			margin: 0 10rpx;
		}


	}

	.displaynone {
		display: none;
	}

	.add {
		width: 100%;
		height: 400rpx;
		background: rqba(236, 237, 238, 1);
		box-shadow: 0px -1rpx 0px 0px rgba(0, 0, 0, 0.1);

		.add-cd {
			padding: 50rpx;
			width: 100%;
			height: 100%;

			.fsdd-d {
				font-size: 20rpx;
				padding-top: 10rpx;
			}

			.fsdd {
				background-color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100rpx;
				height: 100rpx;
				border-radius: 10rpx;


				.fsdd-dd {
					width: 56rpx;
					height: 56rpx;
				}
			}
		}

	}
</style>
